<!DOCTYPE html><html lang="en"><head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Vue</title>
    <link rel="stylesheet" href="/css/common.css">
    <style>
        .info {
            border: 1px solid lightgray;
            padding: 4px;
            border-radius: 2px;
        }
    </style>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14"></script>
</head><body>
<div id="app">
    <h1>{{ appName }}</h1>
    <user-info @ok="doHandleChildEvent"></user-info>
</div>
<script type="text/javascript">
    Vue.component('UserInfo', {
        data: function () { return {account: 'admin'}},
        methods: {
            doTellParent() {
                this.$emit('ok', this.account)
            }
        },
        template: `<div class="info">
                        <span>User info: {{account}}</span>
                        <button @click="doTellParent">告诉父组件</button>
                   </div>`
    })
    const app = new Vue({
        el: '#app',
        data: { appName: 'My App'},
        methods: {
            doHandleChildEvent (param) {
                alert('账号: ' + param)
            }
        }
    })
</script></body></html>
